package com.reds.backend.controller.adminController;
import com.reds.backend.service.admin.adminHandleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/admin/")
public class adminHandleController {

    //private final adminHandleService adminService;
    @Autowired
        adminHandleService adminHandleService;

//    @Autowired
//    public AdminController(adminHandleService adminService) {
//        this.adminService = adminService;
//    }

    @PostMapping("/sendEmail/")
    public String sendEmail(@RequestParam Map<String,String> map) {
        return adminHandleService.sendAdminEmail(map.get("name"),map.get("email"));
    }
    @PostMapping("/register/")
    public String register(@RequestParam Map<String,String> map){
        return adminHandleService.codeCheck(map.get("name"),map.get("password"),map.get("email"),map.get("code"));
    }

    @PostMapping("/login/")
    public Map<String,String> login(@RequestParam Map<String,String> map) {
//        boolean success = adminService.loginAdmin(name, password);
//        return success ? "success" : "failure";

//        JSONObject jsonObject = new JSONObject();
//        jsonObject.put("article",article);//查询到的文章
//        jsonObject.put("address",address);//查询到的地址
//        return  jsonObject;
        return adminHandleService.loginAdmin(map.get("email"),map.get("password"));
    }
}